## The Social Origins of Democracy and Authoritarianism Reconsidered: Prussia and Sweden in Comparison
## by Erik Bengtsson and Felix Kersting
## published in Comparative Political Studies
## Figure 1b


library(sf)
library(ggplot2)
library(tidyverse)
library(patchwork)
library(readxl)
library(haven)
library(tmap)

setwd("")

mapdata <- read_excel("raw/sweden_landinequality.xlsx") 

shape <- st_read("raw/__pgsql2shp2504_tmp_table.shp") 

gdf <- merge(shape, mapdata, by='G_UNIT')

gdf <- gdf %>% mutate(quantiles = as.factor(ntile(s_bigfarms, 10)))
p <- gdf %>% ggplot() + geom_sf(aes(fill = quantiles), size = 0.1)  +
  scale_fill_brewer(palette = "RdYlBu", name = "% Large farms", direction = -1, guide = guide_legend(nrow=2)) +
  theme_void() + theme(legend.position = "bottom")
p
pdf("output/figure1b.pdf")
plot(p)
dev.off()

